package com.kimehwa.studyboot.elasticsearchtest;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Arrays;

/**
 * @author xiaodongguan
 * @description
 * @since 2021-09-21 14:47
 */

public class EstestInsertBatch {
    /*
    增删改查都是要他进行搞起
     */
    public static void main(String[] args) throws IOException {

        // 创建es对象
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("47.105.163.178",9200,"http"))
        );

        BulkRequest bulkRequest = new BulkRequest();



        bulkRequest.add(new IndexRequest().index("user").id("1002").source(XContentType.JSON,"name","zhangsan"));
        bulkRequest.add(new IndexRequest().index("user").id("1002").source(XContentType.JSON,"name","lisi"));
        bulkRequest.add(new IndexRequest().index("user").id("1002").source(XContentType.JSON,"name","wangwu"));


        BulkResponse bulk = esClient.bulk(bulkRequest, RequestOptions.DEFAULT);
        System.out.println(bulk.getTook());
        System.out.println(Arrays.toString(bulk.getItems()));



        esClient.close();



    }
}
